package com.game.service.game.turntable.config;

import com.game.service.app.PostJsonDeal;
import com.game.service.app.Utils;
import com.game.service.define.RoomConfig;
import com.game.service.socket.FileUtils;
import com.game.service.socket.SocketServer;
import com.game.service.windows.LogWindows;

import java.util.ArrayList;

import static com.game.service.app.Utils.LogDate;

public class PrizeList {
    private ArrayList<int[]> prizeArray = new ArrayList<>();
    private ArrayList<int[]> prizeArrayLuckyCard = new ArrayList<>();
    private int[] prizeArrayLuckyValue = new int[10];
    private int prizeLuckyValue;
    private String sign;//幸运积分加密签名
    private long uid;//绑定用户id

    private long dailyTaskWin;//每日任务获得
    private long exLuckyStore;//兑换幸运商店钻石

    public PrizeList(int[] _betArray, long uid) {
        this.uid = uid;
        init(_betArray);
    }

    private void init(int[] _betArray) {
        for (int i = 0; i < _betArray.length; i++) {
            int[] prizeItemCount = new int[16];//出奖统计
            prizeArray.add(prizeItemCount);
        }
        for (int i = 0; i < _betArray.length; i++) {
            int[] prizeCard = new int[10];//生成水晶卡片(LuckyWheel)
            prizeArrayLuckyCard.add(prizeCard);
        }
        String code = String.format("UID=%s@LUCKY_VALUE=%s@KEY=%s", uid, this.prizeLuckyValue, RoomConfig.LUCKY_KEY);
        sign = Utils.encryptMD5(code);//初始化玩家的幸运值签名
    }

    public ArrayList<int[]> getPrizeArray() {
        return prizeArray;
    }

    public void setPrizeArray(ArrayList<int[]> prizeArray) {
        this.prizeArray = prizeArray;
    }

    public ArrayList<int[]> getPrizeArrayLuckyCard() {
        return prizeArrayLuckyCard;
    }

    public void setPrizeArrayLuckyCard(ArrayList<int[]> prizeArrayLuckyCard) {
        this.prizeArrayLuckyCard = prizeArrayLuckyCard;
    }


    public int[] getPrizeArrayLuckyValue() {
        return prizeArrayLuckyValue;
    }

    public void setPrizeArrayLuckyValue(int[] prizeArrayLuckyValue) {
        this.prizeArrayLuckyValue = prizeArrayLuckyValue;
    }

    public int getPrizeLuckyValue() {
        return prizeLuckyValue;
    }

    public void setPrizeLuckyValue(int prizeLuckyValue) {
        this.prizeLuckyValue = prizeLuckyValue;
    }

    public void setPrizeLuckyValueAdd(int prizeLuckyValue) {
        long ll = Utils.checkingLuckyValue(uid, this.prizeLuckyValue, sign);
        if (ll >= 0) {
            this.prizeLuckyValue += prizeLuckyValue;
            String code = String.format("UID=%s@LUCKY_VALUE=%s@KEY=%s", uid, this.prizeLuckyValue, RoomConfig.LUCKY_KEY);
            sign = Utils.encryptMD5(code);
            String log = String.format("@LUCKY_VALUE=%s@SIGN=%s", this.prizeLuckyValue, sign);
            FileUtils.writeTxtToFile(log, LogDate(), SocketServer.getFileName((int) uid));//积分日志写入
            LogWindows.getLogWindows().printToTextArea(log, PrizeList.class);
        }


    }

    public void setPrizeLuckyValueLower(int prizeLuckyValue) {
        long ll = Utils.checkingLuckyValue(uid, this.prizeLuckyValue, sign);
        if (ll >= 0) {
            this.prizeLuckyValue -= prizeLuckyValue;
            String code = String.format("UID=%s@LUCKY_VALUE=%s@KEY=%s", uid, this.prizeLuckyValue, RoomConfig.LUCKY_KEY);
            sign = Utils.encryptMD5(code);
            String log = String.format("@LUCKY_VALUE=%s@SIGN=%s", this.prizeLuckyValue, sign);
            FileUtils.writeTxtToFile(log, LogDate(), SocketServer.getFileName((int) uid));//积分日志写入
            LogWindows.getLogWindows().printToTextArea(log, PrizeList.class);
        }
    }


    public long getDailyTaskWin() {
        return dailyTaskWin;
    }

    public void setDailyTaskWinAdd(long dailyTaskWin) {
        this.dailyTaskWin += dailyTaskWin;
    }

    public long getExLuckyStore() {
        return exLuckyStore;
    }

    public void setExLuckyStoreAdd(long exLuckyStore) {
        this.exLuckyStore += exLuckyStore;
    }

    public String getSign() {
        return sign;
    }

    public long getUid() {
        return uid;
    }
}
